<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>01.通过AJAX读取同域名下的txt目录下的文本内容</title>
		<script>
			window.onload = function () {
				var oBtn = document.getElementsByTagName("input")[0];
				
				oBtn.addEventListener('click', function () {
					var oxhr = null;
					
					try {
						oxhr = new XMLHttpRequest ();
					} catch (e) {
						oxhr = new ActiveXObject(Microsoft.XMLHTTP);
					}
					
					oxhr.addEventListener('readystatechange', function () {
						if ( oxhr.readyState == 4 ) {
							if ( ( oxhr.status >= 200 && oxhr.status < 300 ) || oxhr.status == 304 ) {
								alert(oxhr.responseText);
							}
						}
					}, false);
					
					oxhr.open ('GET', './txt/allen.txt', true);
					oxhr.send(null);
				}, false);
			};
		</script>
	</head>
	<body>
		<input type="button" value="读取内容" />
	</body>
</html>
